
# 安装k8s的准备工作 
# 1.关闭swap 
# 2.关闭selinux
# 3.关闭系统相关功能,比如防火墙
# 4.安装vim
# 5.安装dokcer
# 6.配置docker


# 1.关闭swap 
disable_swap(){
	sed -i 's/\/dev\/mapper\/centos-swap/#\/dev\/mapper\/centos-swap/g' /etc/fstab
	cat /etc/fstab
}

# 2.关闭 selinux 
disable_selinux(){
	sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config
	cat /etc/selinux/config
}

# 3.关闭系统级功能
disabel_sys_func() {
	echo "准备关闭自动启动的应用: $1" 
	systemctl disable $1
}

enabel_sys_func() {
        echo "配置自动启动的应用: $1" 
        systemctl enable $1
}

stop_sys_func() {
        systemctl stop $1
}

start_sys_func() {
        systemctl restart $1
}


# 4.安装vim 
sys_install_func(){
	echo "准备安装软件: $1"
	yum install -y $1
}

# 5.安装docker 
install_docker(){
	yum install -y wget
	yum install -y yum-utils device-mapper-persistent-data lvm2
	yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
	yum install -y docker-ce-19.03.6-3.el7
	sleep 1
	
}

after_install_docker(){
	enabel_sys_func docker
	start_sys_func docker 
	sleep 10
	config_docker 
	sleep 1
}
config_docker(){
	touch /etc/docker/daemon.json
	echo " { " > /etc/docker/daemon.json
	echo " \"registry-mirrors\": [\"http://hub-mirror.c.163.com\",\"https://docker.mirrors.ustc.edu.cn\"] " >> /etc/docker/daemon.json
	echo " } " >> /etc/docker/daemon.json
    sleep 1		

}



disable_swap
disable_selinux
stop_sys_func firewalld
sys_install_func vim
install_docker
after_install_docker
# 重启,根据实际需要.
reboot 